import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
// src/main.js
import { createPinia, PiniaPlugin } from 'pinia'
import router from './router'
import { myPiniaPlugin } from '@/stores/plugins/myPiniaPlugin'
import { ref, toRef } from 'vue'
import { debounce } from 'lodash'
import { PiniaDebounce } from '@pinia/plugin-debounce'
import piniaPluginPersist from 'pinia-plugin-persist'
import '@ui/src/base/base.scss'
import '@ui/src/base/scss/card.scss'
import { Demo, Card } from '@ui/index'
// pinia pplugin

const pinia = createPinia()
const app = createApp(App)
// pinia.use(myPiniaPlugin)
// pinia.use(({ store }) => {
//   const greeting = ref('hello world')
//   store.$state.greeting = greeting // 是为了devTool能够检测到
//   store.greeting = toRef(store.$state, 'greeting')
// })
// 所有store共享状态
// const greeting = ref('hello world')
// pinia.use(({ store }) => {
//   // greeting在所有store之间共享
//   store.$state.greeting = greeting
//   store.greeting = greeting
// })
// const plugin: PiniaPlugin = ({ options, store }) => {
//   if (options.debounce) {
//     return Object.keys(options.debounce).reduce((debounceActions, key) => {
//       debounceActions[key] = debounce(store[key], options.debounce[key])
//       return debounceActions
//     }, {})
//   }
// }
// pinia.use(plugin)

pinia.use(PiniaDebounce(debounce))
pinia.use(piniaPluginPersist)
app.use(pinia)
app.use(router)
app.use(Card)
app.use(Demo)
app.mount('#app')
